<?php

namespace Admin\Controller;

use Zend\Form\Form;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Admin\Service\AdminCaterory as AdminCategoryServive;

class CategoriesController extends AbstractActionController
{
    protected $createCategoryForm;

    /**
     * @var UserService
     */
    protected $categoryService;

    public function indexAction()
    {
         return new ViewModel(array(
            'paginator' => NULL
        ));
    }
    
    /*
     * create categories
    */

    public function createAction()
    {
        $form = $this->getCreateCategoryForm();
        $request = $this->getRequest();
        $adminCategoryService = $this->getCategoryService();

        if($request->isPost()){
            $data = array_merge_recursive(
                $this->getRequest()->getPost()->toArray(),
                $this->getRequest()->getFiles()->toArray()
            );

            $form->setData($data);
            if($form->isValid())
            {

            }
        }
        return array(
            'form' => $form,
        );
    }

    public function getCategoryService()
    {
        if(!$this->categoryService)
        {
            $this->setCategoryService($this->getServiceLocator()->get('admin_category_service'));
        }
        return $this->categoryService;
    }

    public function setCategoryService(AdminCategoryServive $categoryService)
    {
        $this->categoryService = $categoryService;
        return $this;
    }

    public function getCreateCategoryForm()
    {
        if (!$this->createCategoryForm)
        {
            $formManager = $this->getServiceLocator()->get('FormElementManager');
            $form = $formManager->get('Admin\Form\Category\CreateCategoryForm');
            $this->setCreateCategoryForm($form);
            //$this->setCreateCategoryForm($this->getServiceLocator()->get('admin_category_create_form'));
        }
        return $this->createCategoryForm;
    }

    public function setCreateCategoryForm(Form $createCategoryForm)
    {
        $this->createCategoryForm = $createCategoryForm;
        return $this;
    }
}

